package com.nf.health.app.inquiry.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.nf.health.app.R;
import com.nf.health.app.inquiry.bean.InquiryDetailBean;
import com.nf.health.app.utils.DensityUtil;
import com.nf.health.app.utils.ScreentUtils;

/**
 * Created by hepann on 2016/9/26.
 * The only genius that is worth anything is the genius for hard work
 *
 * @author hepann
 * @Description
 * @email he_pann@163.com
 */
public class DetailGridViewAdapter extends BaseAdapter {
    private Context ctx;
    private InquiryDetailBean.ContentBean contentBean;
    private int mWidth;

    public DetailGridViewAdapter(InquiryDetailBean bean, Context ctx) {
        this.ctx = ctx;
        contentBean = bean.getInquiry().getContentBean();
        mWidth = (ScreentUtils.getScreenWidth(ctx) - DensityUtil.dip2px(ctx, 35)) / 5;
    }

    @Override
    public int getCount() {
        return contentBean.getImages().size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        //最多五张图片,不存在复用问题,这里直接返回imageivwe即可
        ImageView iv = new ImageView(ctx);
        //在gridview中要用AbsListView的layoutparams
        AbsListView.LayoutParams params = new AbsListView.LayoutParams(mWidth, mWidth);
        iv.setLayoutParams(params);
        Glide.with(ctx).load(contentBean.getImages().get(position)).placeholder(R.drawable.default_image).centerCrop().into(iv);
        return iv;
    }
}
